package com.huawei.M01.iterator;

/**
 * 表现良好时间段的最大长度
 *
 * @author 111
 */
public class LongestWPI {
    public int longestWPI(int[] hours) {
        int res = 0;
        int tiredDays = 0;
        int ordinaryDays = 0;
        // 使用双指针进行求解
        int fast = 0;
        int slow = 0;
        while (slow < hours.length && fast < hours.length) {
            // 如果大于8小时，则是劳累的一天
            if (hours[fast] > 8) {
                tiredDays++;
            }else {
                ordinaryDays++;
            }
            fast++;
            // 处理指针的前进
            if (tiredDays > ordinaryDays) {
                res = Math.max(res, fast - slow);
            }else {

                if (hours[slow] > 8) {
                    tiredDays--;
                }else {
                    ordinaryDays--;
                }
                slow++;
            }
        }
        return res;
    }


    public static void main(String[] args) {
        LongestWPI longestWPI = new LongestWPI();
        System.out.println(longestWPI.longestWPI(new int[]{6,9,9}));
    }
}
